class Rudoku::FieldSelector
  @@field_selectors = {}
  def self.[](id)
    @@field_selectors[id]
  end
  
  attr_reader :id, :name, :desc, :reason, :fallback, :logic
  
  def initialize(params, &logic)
    # add all rules to the rules hash
    @id, @name, @desc, @reason, @fallback = params[:id], params[:name], params[:desc], params[:reason], params[:fallback]
    @name ||= @id.to_s.gsub("_", " ")
    @logic = logic
    @@field_selectors[@id] = self if @id
  end
  
  def select(sudoku)
    selection = run(sudoku)
    selection = @fallback.select(sudoku) if selection.field.nil? && @fallback
    selection
  end
  
  def run(sudoku)
    FieldSelectorLogicDslProxy.new(self, sudoku).run.field_selection
  end
end
